﻿using DataInit.Entities;
using Stee.CAP8.Entity;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace DataInit.DataContexts.DataSave
{
    public interface IDataSave<T> where T : BaseEntity, new()
    {
        Task Generate(IEnumerable<T> entities);
    }

    public class DataSaver : IDataSave<LoginOperator>, IDataSave<Incident>
    {

        private readonly PTDBContext DBContext;

        public DataSaver(PTDBContext dBContext)
        {
            DBContext = dBContext ?? throw new ArgumentNullException(nameof(dBContext));
        }

        public async Task Generate(IEnumerable<LoginOperator> entities)
        {
            await DBContext.AddRangeAsync(entities);
            await DBContext.SaveChangesAsync();
        }

        public async Task Generate(IEnumerable<Incident> entities)
        {
            await DBContext.AddRangeAsync(entities);
            await DBContext.SaveChangesAsync();
        }
    }
}
